//前端非空验证（标签ID，提示语）
function nonEmpty(input, tips) {
    var inputval = $("#" + input).val();
    if (!inputval) {
        layer.tips('请输入'+tips+'!', '#' + input, {tips: [2, '#CC3333']});
        return false;
    }
    return true;
}

//用户名验证
function accountCheck(input, tips){
    if(nonEmpty(input, tips)){
        // selectUserName(true);

    var account = $("#account").val();
    $.ajax({
        url : "manageWork/accountCheck.action",
        data : {
            "account" : account
        },
        type : "post",
        dataType : "text",
        success : function (result) {
            if (result=="error") {
                    layer.tips('用户名可用！', '#account11', {tips: [2, '#00ff00']});
            } else if (result=="success") {
                layer.tips('用户名已被使用！', '#account11', {tips: [2, '#CC3333']});
            }
        }
    });
    }
}
//密码验证
function pwdCheck(input, tips){
    if (nonEmpty(input, tips)) {
        var password = $("#password").val();
        var password2 = $("#password2").val();
        if (password != password2) {
            layer.tips('密码不一致！', '#password2', {tips: [2, '#CC3333']});
        }
    }
}

//验证年龄
function workAgeCheck(input, tips){
    if(nonEmpty(input, tips)){
        var workAge = $("#workAge").val();
        if(workAge > 150){
            layer.tips('年龄格式有误！', '#workAge', {tips: [2, '#CC3333']});
        };
        if(workAge < 0){
            layer.tips('年龄格式有误！', '#workAge', {tips: [2, '#CC3333']});
        };
    };
}

//手机验证
function modeleCheck(input, tips){
    if (nonEmpty(input, tips)) {
        var inputval = $("#"+input).val();
            if (!inputval.match(/^1[34578]\d{9}$/)) {
                layer.tips('请输入正确的'+tips+'！', '#'+input, {tips: [2, '#CC3333']});
            }
    }
}

//增加内部工作人员
function editWork() {
    if ($("#workAge").val() == "") {
        alert("年龄不能为空！！")
        return;
    };
    if ($("#mobile").val() == "") {
        alert("手机号不能为空！！")
        return;
    };
    if ($("#post").val() == "") {
        alert("职位不能为空！！")
        return;
    };
    if ($("#education").val() == "") {
        alert("学历不能为空！！")
        return;
    };
    if ($("#deskId").val() == "") {
        alert("请选择科室！！")
        return;
    };
    if ($("#roleId").val() == "") {
        alert("请选择角色！！")
        return;
    };
    if($("#workSite").val() == ""){
        alert("住址不能为空！！")
        return;
    };

    $.ajax({
        url : "manageWork/eitWork.action",
        data : $('#form-admin-add').serialize(),
        type : "post",
        dataType : "text",
        success : function (res) {
            if (res == "success") {
                layer.msg("修改成功！！", {icon: 6, time: 1000}, function () {
                    layer.closeAll(layer.index);
                    window.parent.location.reload()
                });
            } else if (res == "error") {
                layer.msg("修改失败！！", {icon: 6, time: 1000}, function () {
                    layer.closeAll(layer.index);
                    window.parent.location.reload()
                });
            }
        }
    });


    /*else{
                                console.log("333")
                                $.post("manageWork/eitWork.action",
                                    $('#form-admin-add').serialize(),
                                    function (res) {
                                        if (res == "success") {
                                            layer.msg("修改成功！！", {icon: 6, time: 1000}, function () {
                                                layer.closeAll(layer.index);
                                                window.parent.location.reload()
                                            });
                                        } else if (res == "error") {
                                            layer.msg("修改失败！！", {icon: 6, time: 1000}, function () {
                                                layer.closeAll(layer.index);
                                                window.parent.location.reload()
                                            });
                                        }
                                    }
                                )
                            }*/
}

